package com.share.finance.fund.web;

import com.share.common.common.Page;
import com.share.common.common.Result;
import com.share.finance.fund.model.db.RepaymentPlan;
import com.share.finance.fund.model.vo.RepaymentPlanPageReq;
import com.share.finance.fund.service.IRepaymentPlanService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 还款计划  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-27
 */
@Slf4j
@RestController
@RequestMapping("/repayPlan")
public class RepaymentPlanController {

    @Autowired
    private IRepaymentPlanService iRepaymentPlanService;


    @ApiOperation(value = " 模拟 生成还款记录 并更新 还款计划")
    @RequestMapping(value = "/genRepayRecord")
    public Result<Object> genRepayRecord() {
        try {
            Object res = iRepaymentPlanService.genRepayRecord();
            return Result.success(res);
        } catch (Exception e) {
            log.error("触发模拟放款 和 生成还款计划 失败");
            return Result.failure(e.getMessage());
        }
    }

    @ApiOperation(value = "计算逾期状态")
    @RequestMapping(value = "/callOverdueStatus")
    public Result<Object> callOverdueStatus(Long id) {
        try {
            Object res = iRepaymentPlanService.callOverdueStatus(id);
            return Result.success(res);
        } catch (Exception e) {
            log.error("计算逾期状态 失败");
            return Result.failure(e.getMessage());
        }
    }

    @ApiOperation(value = "分页列表")
    @RequestMapping(value = "/pageList")
    public Result<Page<RepaymentPlan>> pageList(RepaymentPlanPageReq req) {
        Page<RepaymentPlan> page = iRepaymentPlanService.pageList(req);
        return Result.success(page);
    }
}
